package gui.crud;

import gui.AbstractFramePythagoras;
import gui.Menu;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

public abstract class AbstractRegisterPanel extends JPanel {
	private JButton registerButton, toMenuButton;
	private JTextField nameField;
	
	private JLabel labelForName;
	
	private String title;
	

	public AbstractRegisterPanel(String title) {
		this(title, 800, 600);	
	}
	
	public AbstractRegisterPanel(String title, int width, int height) {
		this.title = title;
		
		this.setSize(width, height);
		this.setLayout(null);
		
		
		this.registerButton = new JButton("Cadastrar");
		this.toMenuButton = new JButton("Menu");
		this.nameField = new JTextField();
		this.labelForName = new JLabel("<html><i><b>Nome:</b></i></html>");
		
		this.registerButton.setBounds((width/2) - 55, height - 120, 110, 25);
		this.toMenuButton.setBounds((width/2) - 55, height - 80, 110, 25);
		this.nameField.setBounds(60, 60, 120, 20);
		this.labelForName.setBounds(60, 38, 120, 20);
		
		this.registerButton.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				registerAct();
			}
		});
		
		this.toMenuButton.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				toMenu();
			}
		});
		
		
		
		this.add(registerButton);
		this.add(toMenuButton);
		this.add(nameField);
		this.add(labelForName);
		
		setUpNewComponents();
		addNewComponents();
		
	}
	
	

	protected JButton getRegisterButton() {
		return registerButton;
	}

	protected void setRegisterButton(JButton registerButton) {
		this.registerButton = registerButton;
	}

	protected JTextField getNameField() {
		return nameField;
	}

	protected void setNameField(JTextField nameField) {
		this.nameField = nameField;
	}

	
	public String getTitle() {
		return title;
	}

	protected void setTitle(String title) {
		this.title = title;
	}

	
	protected void toMenu() {
		Menu m = new Menu();
		((AbstractFramePythagoras) this.getTopLevelAncestor()).changePanel(m, m.getTitle());
	}
	
	protected abstract void registerAct();
	
	protected abstract void setUpNewComponents();
	
	protected abstract void addNewComponents();
	
}
